package com.zengqingfa.springboot.es.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @fileName: ElasticsearchClientConfig
 * @author:
 * @date: 2020-7-2 13:45
 * @description:
 */
@Configuration
public class ElasticsearchClientConfig {

    /**
     * 集群配置
     *
     * @return
     */
    //@Bean
    public RestHighLevelClient restHighLevelClient1() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("127.0.0.1", 9201, "http"),
                        new HttpHost("127.0.0.1", 9202, "http"),
                        new HttpHost("127.0.0.1", 9203, "http")));
        return client;
    }

    /**
     * 单机配置
     *
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("127.0.0.1", 9200, "http")
                ));
        return client;
    }


}
